/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kurvykurvy.page;

import com.kurvykurvy.image.*;
import com.kurvykurvy.actions.LoadImageAction;
import com.kurvykurvy.image.ImageLoader;
import com.kurvykurvy.image.LoadedImage;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Image;
import java.util.Iterator;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

/**
 *
 * @author HY
 */
public class PageLayoutTemplateFilmStrip
    extends JPanel
{
    public static int SMALL_ICON_SIZE =120;
    public static int MEDIUM_ICON_SIZE = 200;

    JScrollPane scroller;
    JPanel imagePanel;

    public PageLayoutTemplateFilmStrip()
    {
        initComponents();
    }

    protected void initComponents()
    {
        imagePanel = new JPanel( true );
        scroller = new JScrollPane( imagePanel );

        imagePanel.setLayout(  new FlowLayout() );
        imagePanel.setBackground( Color.WHITE );
        ( (FlowLayout) imagePanel.getLayout() ).setAlignment( FlowLayout.LEFT );
        this.setLayout( new BorderLayout() );
        this.add( scroller, BorderLayout.CENTER );
        this.setBackground( Color.WHITE );
    }

    public void loadImages()
    {
        ImageLoader loader = ImageLoader.getInstance();

        int i = 0;
        for( Iterator<LoadedImage> it = loader.getImages().iterator(); it.hasNext(); )
        {
            LoadedImage img = it.next();
            if( img.getImage() != null )
            {
                ImageIcon icon = new ImageIcon( img.getImage().getScaledInstance( SMALL_ICON_SIZE, SMALL_ICON_SIZE, Image.SCALE_SMOOTH )  );
                JLabel label = new JLabel( img.getFilename(), icon, SwingConstants.CENTER );
                label.setHorizontalTextPosition( SwingConstants.CENTER );
                label.setVerticalTextPosition( SwingConstants.BOTTOM );
                label.setIcon( icon );
                this.imagePanel.add( label );
            }
        }
    }

    public static void main( String[] args )
    {
        JFrame mainFrame = new JFrame( "ImageSelectionPanel" );
        mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

        PageLayoutTemplateFilmStrip panel = new PageLayoutTemplateFilmStrip();

        LoadImageAction action = new LoadImageAction();
        action.loadImages();

        panel.loadImages();

        mainFrame.getContentPane().setLayout( new BorderLayout() );
        mainFrame.getContentPane().add( panel );

        mainFrame.setSize(  640, 480 );
        mainFrame.setVisible(  true );
    }
}
